<?php
class RedisMQ{
    protected $_redis;
    static protected $_instance;

    public function __construct(){
        $redis = new Redis();
        $redis->connect(DXW_REDIS_ADDR,DXW_REDIS_PORT);
        $redis->auth(DXW_REDIS_PWD);
        $redis->select(DXW_REDIS_DB_INDEX);
        $this->_redis = $redis;
    }

    public function set_col($name){
        $this->_redis->select($name);
        return $this;
    }
    public function set($key,$value){
        $this->_redis->rPush($key,$value);
        return $this;
    }

    public function get($key){
       return  $this->_redis->rPop($key);
    }


    public static function create(){
        if(null === self::$_instance){
            self::$_instance = new self;
        }
        return self::$_instance;
    }
    public function add_col($name){
        $this->_redis->sAdd($name);
        return $this;
    }
    public function get_col($name){
        return $this->_redis->sContains($name);
    }
     public function size($key){
        return $this->_redis->zSize($key);
    }

    public function delete($key){
        return $this->_redis->delete($key);
    }
    public function getAll($key,$start=0,$end ="-1"){
        return $this->_redis->lRange($key,$start,$end);
    }
}